package main.Q2201_2300;

import java.util.List;

public class Q2221_2230 {
    public static void main(String[] args) {
        System.out.println("Question2221：数组的三角和");
        int[] nums=new int[]{1,2,3,4,5};
        System.out.println(new Question2221().triangularSum(nums));
        System.out.println("Question2222：");
        System.out.println("Question2223：");
        System.out.println("Question2224：");
        System.out.println("Question2225：");
        System.out.println("Question2226：");
        System.out.println("Question2227：");
        System.out.println("Question2228：");
        System.out.println("Question2229：");
        System.out.println("Question2230：");
    }
}

class Question2221 {
    int result = 0;

    public void process(int[] nums) {
        if (nums.length == 1) {
            result = nums[0];
            return;
        }
        int[] curArr = new int[nums.length - 1];
        for (int i = 0; i < curArr.length; i++) {
            String s = String.valueOf(nums[i] + nums[i + 1]);
            curArr[i] =  s.charAt(s.length()-1)-'0';
        }
        process(curArr);
    }

    public int triangularSum(int[] nums) {
        process(nums);
        return result;
    }
}